function checkyushen(id) {
    $.get(baseURL + "sys/tianan/info/" + id, function (r) {
        vm.tianan = r.tianan;
        layer.open({
            title: vm.tianan.title,
            shade: 0.5,
            type: 1,
            skin: 'layui-layer-molv',
            area: ['800px', '470px'],
            btn: ['确定'],
            content: '<form id="test"><div id="test1" style="padding:10px 10px  0 10px">' +
                '<p class="  " style="text-align: center;" > 案由分析</p>' +
                '<div class="form-group wenzi anyoufenxi" style="border: 1px #999 solid;"></div>' +
                '<p   style="text-align: center;" > 措施建议</p>' +
                '<div class="form-group wenzi  cuoshijianyi" style="border: 1px #999 solid;">' + '</div> ' +
                '<div class=" wenzi renyuan" style=""></div>' +
                '<div class="tuihui" style="color: red;"></div>' +
                '<div class="form-group" style="line-height: 35px; margin-bottom: 0">办理类型：' +
                '      <input type="radio" class="check" checked style="margin: 0 10px" name="lian" value="1" title="立案">立案' +
                '      <input type="radio" class="check" style="margin: 0 10px" name="lian" value="2" title="解释" >解释' +
                '      <input type="radio" class="check" style="margin: 0 10px" name="lian" value="3" title="不立案" >不立案</div>' +
                '<div class="form-group depts " style="margin: 5px;">办理时限：<input id="endtime" type="date"/>&nbsp;&nbsp;' +
                '办理部门：<select class="dept selectpicker"  data-live-search="true"></select></div></div>' +
                '<div class="form-group shuru" style="display: none; margin: 10px;" ><textarea  name=""  placeholder="不立案原因" class="layui-textarea  liancause"></textarea></div>' +
                '</form>',
            success: function (layero, index) {
                //评分组件代码
                $(".anyoufenxi").html("<p>" + vm.tianan.anyoufenxi + "</p>");
                $(".cuoshijianyi").html("<p>" + vm.tianan.cuoshijianyi + "</p>");
                if (vm.tianan.lianstatus == 3) {
                    $('.tuihui').html("<p>退回部门：" + vm.tianan.liandeptname + "</p><p>原因：" + vm.tianan.bujieshou+"</p>");
                } else {
                    $('.tuihui').hide();
                }
                $(".renyuan").html("<p>提案人：" + vm.tianan.creatusername + "&nbsp;&nbsp;&nbsp;所属部门：" + vm.tianan.deptIdName + "</p>")
                var dict = getDeptAlls('');
                var sel = "";
                sel += '<option  value=""> 请选择</option>'
                for (var i = 0; i < dict.length; i++) {
                    sel += '<option  value="' + dict[i].deptId + '">' + dict[i].name + '</option>'
                }
                var endtime = getconfig('endtime');
                $("#endtime").val(endtime);
                $(".liancause").val(vm.tianan.liancause);
                $(".dept").html(sel);
                $('.dept').selectpicker('refresh');
                $(".check").click(function () {
                    if ($(this).val() == 1 || $(this).val() == 2) {
                        $(".shuru").hide();
                        $(".depts").show();
                        $(".endtime").show();
                    } else {
                        $(".depts").hide();
                        $(".shuru").show();
                        $(".endtime").hide();
                    }
                })

            },
            //确认回调
            btn1: function () {
                vm.tianan.lianstatus = 1;
                vm.tianan.liantype = $(".check[type='radio']:checked").val();
                if (vm.tianan.liantype == '3') {
                    vm.tianan.banjiestatus = 6;
                    vm.tianan.liandept = 0;
                } else {
                    vm.tianan.liandept = $(".dept").selectpicker('val');

                }
                vm.tianan.liancause = $(".liancause").val();
                vm.tianan.endtime = $("#endtime").val();
                var url = "sys/tianan/updateyushen";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.tianan),
                    success: function (r) {
                        if (r.code === 0) {
                            layer.msg("提交成功", {icon: 1});
                            vm.reload();
                        } else {
                            layer.alert(r.msg);

                        }
                    }
                });
                layer.closeAll()
            },


        });
    });

}

function init() {

    $("#jqGridtable").html("");
    $("#jqGridtable").html('<table id="jqGrid"></table><div id="jqGridPager"></div>');
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/tianan/listlian?sea=' + $("#sea").val() + '&lianstatus=' + $("#lianstatus").val() + '&liantype=' + $("#liantype").val(),
        datatype: "json",
        colModel: [
            {label: '提案名称', name: 'title', index: 'title', width: 80},
            {
                label: '提案类别',
                name: 'typesName',
                index: 'typesName',
                align: 'center',
                width: 40
            },
            {label: '提案人', align: 'center', sortable: true, name: 'creatusername', index: 'dept_id', width: 40},
            {
                label: '立案类型',
                align: 'center',
                sortable: true,
                name: 'liantype',
                index: 'liantype',
                width: 40,
                formatter: function (value, row, rowObject) {

                    return lian(value);
                }
            },
            {label: '标签', name: 'lable', align: 'center', sortable: true, index: 'lable', width: 30},

            {
                label: '状态', align: 'center', sortable: true, name: 'lianstatus', index: 'lianstatus', width: 40,

                formatter: function (value, row, rowObject) {
                    if (rowObject.lianstatus != 2) {
                        return lianstatus(rowObject.lianstatus);
                    } else {
                        return checkstatus(rowObject.banjiestatus);
                    }

                }
            },
            {label: '办理部门', name: 'liandeptname', align: 'center', sortable: true, index: 'liandeptname', width: 40},

            {
                label: '操作',
                name: 'id',
                align: 'center',
                index: 'id',
                width: 40,
                formatter: function (value, row, rowObject) {
                    var but = "";
                    but += ' <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" onclick="info(' + value + ')">详情</button>';
                    if (rowObject.lianstatus == 0 || rowObject.lianstatus == 3) {
                        but += '<button type="button" class="layui-btn layui-btn-xs layui-btn-normal" onclick="checkyushen(' + value + ')">立案</button>';
                    }
                    return but;
                }
            }


        ],
        viewrecords: true,
        height: 360,
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });
}

$(function () {
    init();
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        tiananShenyi: {},
        tianan: {}
    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.tiananShenyi = {};
        },
        update: function (event) {
            var id = getSelectedRow();
            if (id == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id)
        },
        saveOrUpdate: function (event) {
            $('#btnSaveOrUpdate').button('loading').delay(1000).queue(function () {
                var url = vm.tiananShenyi.id == null ? "sys/tiananshenyi/save" : "sys/tiananshenyi/update";
                $.ajax({
                    type: "POST",
                    url: baseURL + url,
                    contentType: "application/json",
                    data: JSON.stringify(vm.tiananShenyi),
                    success: function (r) {
                        if (r.code === 0) {
                            layer.msg("操作成功", {icon: 1});
                            vm.reload();
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        } else {
                            layer.alert(r.msg);
                            $('#btnSaveOrUpdate').button('reset');
                            $('#btnSaveOrUpdate').dequeue();
                        }
                    }
                });
            });
        },
        del: function (event) {
            var ids = getSelectedRows();
            if (ids == null) {
                return;
            }
            var lock = false;
            layer.confirm('确定要删除选中的记录？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                if (!lock) {
                    lock = true;
                    $.ajax({
                        type: "POST",
                        url: baseURL + "sys/tiananshenyi/delete",
                        contentType: "application/json",
                        data: JSON.stringify(ids),
                        success: function (r) {
                            if (r.code == 0) {
                                layer.msg("操作成功", {icon: 1});
                                $("#jqGrid").trigger("reloadGrid");
                            } else {
                                layer.alert(r.msg);
                            }
                        }
                    });
                }
            }, function () {
            });
        },
        getInfo: function (id) {
            $.get(baseURL + "sys/tiananshenyi/info/" + id, function (r) {
                vm.tiananShenyi = r.tiananShenyi;
            });
        },
        gettiananInfo: function (id) {

        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                page: page
            }).trigger("reloadGrid");
        }
    }
});